package com.jms.fu.action;



import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.jms.fu.exception.DAOException;
import com.jms.fu.form.ProjectForm;
import com.jms.fu.model.bo.ProjectBO;



public class CreateProjectAction extends Action {
	private static Logger logger = Logger.getLogger(LoginAction.class);

	/**
	 * Method execute, called when executing the action
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
			ProjectForm projectForm = (ProjectForm) form;
			HttpSession session = request.getSession();
			ProjectBO projectBO = new ProjectBO();
			String managerId= (String)session.getAttribute("username");
			String name = projectForm.getName();
			String datecreate = projectForm.getDatecreate();
		
			
			
		
			
			try {
				if (projectBO.checkName(name)) {
					request.setAttribute("info", "Project name is exits");
					return mapping.findForward("failed");
					
				}
				projectBO.createNewProject(name,managerId,datecreate);
				request.setAttribute("info", "Project Created");
				return mapping.findForward("success");
				
			} catch (DAOException e) {
				logger.error(e.getMessage());
				return mapping.findForward("error");
			}

	}
}
